package com.gitee.shigen.lucene.runner;

import com.gitee.shigen.lucene.service.LuceneService;
import com.gitee.shigen.lucene.vo.Content;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 项目启动之后同步数据库
 *
 * @author shigenfu
 * @date 2023/12/16 21:37
 */
@Component
@Order(value = 1)
public class ContentRunner implements ApplicationRunner {

    @Resource
    private LuceneService luceneService;

    @Override
    public void run(ApplicationArguments args) {
        // 清空旧数据
        luceneService.deleteAll();
        List<Content> fakeData = luceneService.getFakeData(10);
        luceneService.save(fakeData);
    }
}
